package com.pse.crawler;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.pse.model.Event;
import com.pse.service.CrawlerService;
import com.pse.service.DatesService;
import com.pse.service.EventService;

import us.codecraft.webmagic.Spider;

@Component
public class Crawler {
	
	@Autowired
	private Cpipe cpipe;
	@Autowired
	private EventService eservice;
	@Autowired
	private DatesService dservice;
	@Autowired
	private CrawlerService cservice;
	
	@Scheduled(cron = "0 0/1 * * * ?")
	public void craw(){
		Spider.create(new Cprocessor()).addUrl("http://ft.whepb.gov.cn:8090/Default.aspx")
		.addPipeline(cpipe).thread(1).run();
		List<Event> eidlist = eservice.queryid();
		int a=0,b=0;
		for(Event ee:eidlist){
			a = dservice.queryavr(ee.getEid());//得到用户上传数据的平均值
			b = cservice.query(ee.getLocat());
			a = (a+b)>>1;
			ee.setAqs(a);
			eservice.updates(ee);
		}
		
	}

}
